package com.fengzan.hadoop.shellexcute;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ShellExcute {

    public static void excuteShell(String command){
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(command);
        } catch (IOException e) {
            e.printStackTrace();
        }
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        try {
            String a=null;
            while ( null != (a=bufferedReader.readLine()) ){
                System.out.println(a);
            };
            bufferedReader.close();     // 关闭缓冲流
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            // 阻塞当前线程，直到 command 命令执行完毕
            process.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
